package com.ticket.sass.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ticket.sass.admin.dto.input.coupons.CouponListInput;
import com.ticket.sass.admin.mapper.CouponMapper;
import com.ticket.sass.admin.service.BaseService;
import com.ticket.sass.common.entity.tenant.CouponEntity;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 优惠券表 服务实现类
 * </p>
 *
 * @author ywb
 * @since 2024-03-13
 */
@Service
public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponEntity> implements BaseService<CouponEntity> {
    public IPage<CouponEntity> iPage(CouponListInput input) {
        Page<CouponEntity> page = new Page<>(input.getPageNum(), input.getPageSize());
        QueryWrapper<CouponEntity> queryWrapper = new QueryWrapper<>();
        
        if (input.getName() != null && !input.getName().isEmpty()) {
            queryWrapper.like("name", input.getName());
        }
        if (input.getScenes() != null && !input.getScenes().isEmpty()) {
            queryWrapper.in("scene", input.getScenes());
        }
        if (input.getTypes() != null && !input.getTypes().isEmpty()) {
            queryWrapper.in("type", input.getTypes());
        }
        queryWrapper.orderByDesc("id");
        return this.page(page, queryWrapper);
    }
}
